package com.itheima.case2.utils;

import com.itheima.case2.pojo.po.UserLogin;
import com.itheima.case2.pojo.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/exitLoginServlet")
public class ExitLoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        UserLogin user =(UserLogin) session.getAttribute("user");
        if (user==null){
            //如果为空,提示还未登录
            BaseController.printResult(response,new Result(false,"你还未登录，请先登录！"));
        }else {
            //如果登录了删除user的Session域
            //移除Session域，退出登录
            request.getSession().removeAttribute("user");
            BaseController.printResult(response,new Result(false,"退出登录成功！"));
        }

    }
}